<template>
	<view class="content">
		<view class="Lu-F-header" style="">
			<view class="Lu-F-headTitle">
				趣一点
			</view>
			<view class="clearfix">
				<view class="Lu-F-address fl"  @click="oncity">
					<!-- <image src="/static/image/address.png"></image> -->
					<text class="iconfont icon-dingwei1"></text>
					<text>{{city}}</text>
				</view>
				<popup-layer ref="popupRef" :direction="'right'">
					<view style="width:750upx;height: 100%;">
						<citySelect @back_city="back_city"></citySelect>
					</view>
				</popup-layer>
				<view class="Lu-F-search fl">
					<image src="/static/search.png" class="Lu-F-searchImg"></image>
					<input type="text" v-model="searchcontent" @confirm="search()" class="Lu-F-searchInput" placeholder="搜索商家" placeholder-style="color:#a6a7ab">
					<text class="iconfont icon-close Lu-F-iconclose" @click="closesearch" v-show="searchcontent"></text>
				</view>
			</view>
			<view class="Lu-F-banner">
				<swiper style="height: 320rpx;" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
					<swiper-item v-for="(item,index) in bannerImg" :key="index" @click="bannernavTo(item.url)">
						<image :src='apiUrl + item.pic_url' class="Lu-F-bannerImg"></image>
					</swiper-item>
					
				</swiper>
			</view>
		</view>
		<view class="Lu-F-Lists">
			<view class="Lu-F-List">
				<view class="Lu-F-TOP clearfix">
					<view class="Lu-F-Apply fl" @click="navTo(classification[0].id)">
						<view class="Lu-F-title">趣{{classification[0].name}}</view>
						<view class="Lu-F-english">APPLY COURSES</view>
					</view>
					<view class="Lu-F-Bea fl" @click="navTo(classification[1].id)" v-if="classification.length>1">
						<view class="Lu-F-title">趣{{classification[1].name}}</view>
						<view class="Lu-F-english">BEAUTIFY</view>
					</view>
				</view>
				<view class="Lu-F-Bottom clearfix">
					<view class="Lu-F-School fl" @click="navTo(classification[2].id)" v-if="classification.length>2">
						<view class="Lu-F-title">趣{{classification[2].name}}</view>
						<view class="Lu-F-english">GO TO SCHOOL</view>
					</view>
					<view class="Lu-F-Fitness fl" @click="navTo(classification[3].id)" v-if="classification.length>3">
						<view class="Lu-F-title">趣{{classification[3].name}}</view>
						<view class="Lu-F-english">FITNESS</view>
					</view>
					<view class="Lu-F-mm fl">
						<view>
							<view class="Lu-F-play" @click="navTo(classification[4].id)" v-if="classification.length>4">
								<view class="Lu-F-title1">趣{{classification[4].name}}</view>
								<view class="Lu-F-english1">PLAY</view>
							</view>
							<view class="Lu-F-more" @click="navTo(classification[0].id)" v-if="classification.length>4">
								<view class="Lu-F-title1">更多</view>
								<view class="Lu-F-english1">MORE</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="Lu-F-Bullets">
			<view class="Lu-F-Bullets1">
				<swiper style="height: 120rpx;" :autoplay="true" display-multiple-items="3" :vertical="true" :interval="2000" :duration="1000">
					<swiper-item class="Lu-F-Bullet" v-for="(item,index) in BulletinList" :key="index">
						<view class="swiper-item">
							<image class="Lu-F-BulletImg" src='/static/laba.png'></image><text class="Lu-F-BulletTit">·{{item.str}}</text>
						</view>
					</swiper-item>
				</swiper>
			</view>
		</view>
		<view class="Lu-F-Populars">
			<view class="Lu-F-Popular Lu-F-Popular2">
				<image src="/static/bluex.png"></image>
				<h3>人气商家推荐</h3>
			</view>
			<view class="uni-padding-wrap uni-common-mt">
				<view class="clearfix">
					<!-- <scroll-view scroll-x="true" class="kite-classify-scroll">
						<view class="kite-classify-cell" v-for="(item,index) in Popularbusinessman" :key="index" @click="NavToshang(item)">
							<image class="Lu-F-PopularImg" :src="apiUrl + item.pic" mode="aspectFill"></image>
							<view class="Lu-F-PopularTitle">
								<view class="Lu-F-Popularname">{{item.name}}</view>
								<view class="Lu-F-Populargo">立即前往</view>
							</view>
						</view>
					</scroll-view> -->
					<view class="Lu-index-renqiList" v-for="(item,index) in Popularbusinessman" :key="index" @click="NavToshang(item)" v-if="index < 2">
						<image :src="apiUrl + item.pic" mode="aspectFill" class="Lu-index-img"></image>
						<view class="Lu-index-infor">
							<view>
								<view class="Lu-index-inforname">{{item.name}}</view>
								<view class="Lu-index-infordes">{{item.describe}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="Lu-F-Populars Lu-F-Populars1">
			<view class="Lu-F-Popular">
				<image src="/static/bluex.png"></image>
				<h3>附近商家</h3>
				<view class="Lu-F-Popularmore" @click="navTo(classification[0].id)">更多</view>
			</view>
			<view class="campus-box">
				<view class="campus-item" v-for="(item,index) in Nearbybusinesses" :key="index" @click="NavToshang(item)">
					<view class="campus-media">
						<image class="campus-logo" :src="apiUrl + item.pic"></image>
					</view>
					<view class="campus-body">
						<view class="campus-title">{{item.name}}</view>
						<view class="campus-desc">{{item.describe}}</view>
						<view class="campus-footer">
							<text class="iconfont icon-dingwei"></text>{{item.address}}</text>
						</view>
					</view>
				</view>
			</view>
				
		</view>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import citySelect from '@/components/linzq-citySelect/linzq-citySelect.vue';
	import popupLayer from '@/components/popup-layer/popup-layer.vue';
	export default {
		computed: {
			...mapState(['hasLogin','userInfo','openId','apiUrl'])
		},
		components: {
			citySelect,
			popupLayer
		},
		data() {
			return {
				city:'',  //城市
				district:''  ,//区
				bannerImg:[],  //banner图
				classification:[],  //分类
				BulletinList:[],  //通告栏
				Popularbusinessman:[],  //人气商家
				Nearbybusinesses:[],  //附近商家
				searchcontent:''  ,//搜索内容
				lat1:'',    //纬度
				lng1:''    ,//经度
				markers: [], 
				rgcData: {} 
			}
		},
		onLoad() {
			var that = this;
			// 新建百度地图对象 
			var BMap = new bmap.BMapWX({ 
				ak: 'ltlvEup6U0q4wTl1dLsR8s8W22eNRIGT' 
			}); 
			var fail = function(data) { 
				console.log(data) 
			}; 
			var success = function(data) { 
				console.log(data)
				wxMarkerData = data.wxMarkerData; 
				that.markers=wxMarkerData 
				that.lat1=wxMarkerData[0].latitude 
				that.lng1=wxMarkerData[0].longitude 
				console.log(that.lat1)
				console.log(that.lng1)
			} 
			// 发起geocoding检索请求 
			BMap.geocoding({ 
				address: that.city, 
				fail: fail, 
				success: success, 
				iconPath: '../../img/marker_red.png', 
				iconTapPath: '../../img/marker_red.png' 
			}); 
			
		},
		onShow:function(){
			this.getAddress()  //获取位置
			this.getBannerImge()  //获取banner图
			this.getBulletinList()  //获取通告栏公告
			this.getPopularbusinessman()  //获取人气商家
			this.getclassification()  //获取分类
			
		},
		methods: {
			oncity() {
				var that = this
				this.$refs.popupRef.show();
			},
			closesearch(){
				this.searchcontent = ''
			},
			back_city(e,m) {
				if (e !== 'no') {
					this.city = e.cityName
					this.$refs.popupRef.close();
				} else {
					this.$refs.popupRef.close();
				}
				this.lat1 = m[0].latitude
				this.lng1 = m[0].longitude
				uni.request({
					url:this.apiUrl+"api/get_agent_list",
					data:{
						lat1:this.lat1,
						lng1:this.lng1,
						page:1,
						size:10
					},
					header:{
						openId:this.openId
					},
					method:"POST",
					success: (res) => {
						this.Nearbybusinesses = res.data.data
					}  //获取附近商家推荐
				})
			},
			bannernavTo:function(url){
			
	
				if (!this.hasLogin) {
					// this.wxGetUserInfo()
					uni.showModal({
						title: '未登录',
						content: '请授权登录',
						success: function (res) {
							if (res.confirm) {
							   
							} else if (res.cancel) {
								
							}
						}
					})
				}else{
					if(url == '/pages/classification/index'){
						uni.switchTab({
							url:url
						})
					}else{
						uni.navigateTo({
							url: url
						})
					}
					
				}
				
			},
			navTo:function(id){
				uni.switchTab({
					url:'/pages/classification/index'
				})
				this.$store.commit('settabbar', id);
			},
			NavToshang:function(item){
				uni.navigateTo({
					url: `/pages/classification/merchant?id=${item.id}`
				})
			},
			getBannerImge:function(){
				console.log(this.openId)
				uni.request({
					url:this.apiUrl+"api/banner_list",
					data:{
						type:'1'
					},
					header:{
						openId:this.openId
					},
					method:"POST",
					success: (res) => {
						this.bannerImg = res.data.data
					}
				})
			},  //获取首页轮播图
			getAddress:function(){
				uni.getLocation({
					//#ifdef APP-PLUS
				    type: 'wgs84',
					//#endif
					//#ifdef MP-WEIXIN
					type: 'gcj02',
					//#endif
					geocode:'true',
				    success: (res) => {
				        console.log('当前位置的经度：' + res.longitude);
				        console.log('当前位置的纬度：' + res.latitude);
						
						//#ifdef APP-PLUS
						this.city = res.address.city;
						this.district = res.address.district;
						//#endif
						//#ifdef MP-WEIXIN
						const location = res.latitude + ',' + res.longitude
						uni.request({
							url:'https://apis.map.qq.com/ws/geocoder/v1/',
							data:{
								location:location,
								key:'XVLBZ-BSU66-ULJSQ-MFGXD-TM7GZ-55F2M',
								get_poi:'1'
							},
							method: 'GET',
							success: (res) => {
								console.log(res)
								if (res.statusCode == 200 && res.data.status == 0) {
								// 从返回值中提取需要的业务地理信息数据			  
									this.city = res.data.result.address_component.city;
									this.district=res.data.result.address_component.district;
								}
							}
						})
						//#endif
						this.lat1 = res.latitude
						this.lng1 = res.longitude
						
						uni.request({
							url:this.apiUrl+"api/get_agent_list",
							data:{
								lat1:this.lat1,
								lng1:this.lng1,
								page:1,
								size:10
							},
							header:{
								openId:this.openId
							},
							method:"POST",
							success: (res) => {
								this.Nearbybusinesses = res.data.data
							}  //获取附近商家推荐
						})
						
				    }
				});
			},
			scroll: function(e) {
				console.log(e)
				this.old.scrollTop = e.detail.scrollTop
			},
			getclassification:function(){
				uni.request({
					url:this.apiUrl+"api/get_column",
					data:{
						
					},
					header:{
						openId:this.openId
					},
					method:"POST",
					success: (res) => {
						this.classification = res.data.data
					}
				})
			},  //获取首页分类
			getBulletinList:function(){
				uni.request({
					url:this.apiUrl+"api/get_notices",
					data:{},
					header:{
						openId:this.openId
					},
					method:"POST",
					success: (res) => {
						this.BulletinList = res.data.data
					}
				})
			},  //获取首页公告
			getPopularbusinessman:function(){
				uni.request({
					url:this.apiUrl+"api/agent_list",
					data:{},
					header:{
						openId:this.openId
					},
					method:"POST",
					success: (res) => {
						this.Popularbusinessman = res.data.data
					}
				})
			},  //获取首页人气商家推荐
			
			search:function(){
				uni.navigateTo({
					url: `/pages/classification/search?content=${this.searchcontent}`
				})
			}
			
		},
		beforeCreate() {
			
		},
		created() {
			
		}
	}
</script>

<style lang="scss">
	.content{
		background-color: #F5F5F5;
	}
	.fl{
		float: left;
	}
	.fr{
		float: right;
	}
	.clearfix:after {  
	    content: "."; 
	    display: block; 
	    height: 0; 
	    clear: both; 
	    visibility: hidden;  
	}  
	.Lu-F-box{
		padding: 20rpx;
	}
	.Lu-F-header{
		background-color: #f5f5f5;
		background-size: auto 380rpx;
		background-repeat: no-repeat;
		height: 550rpx;
		background-image: url('~@/static/headerbg.png');
	}
	.Lu-F-headTitle{
		font-size: 40rpx;
		/* font-family: "宋体"; */
		font-weight: 600;
		color: #ffffff;
		text-align: center;
		padding: 40rpx 0;
	}
	.Lu-F-address{
		padding: 0 20rpx;
	}
	.Lu-F-address image{
		width: 22rpx;
		height: 28rpx;
		margin-left: 8rpx;
		margin-right: 14rpx;
	}
	.Lu-F-address text{
		font-size: 30rpx;
		color: #ffffff;
	}
	.kite-classify-scroll{
	    width: 100%;
		height: 300rpx;
		overflow: hidden;
	 	white-space: nowrap;
	}
	.kite-classify-cell{
		display: inline-block;
		width: 80%;
		height: 280rpx;
	}
	/deep/.uni-scroll-view::-webkit-scrollbar {
		/* 隐藏滚动条，但依旧具备可以滚动的功能 */
		display: none
	}
	.Lu-F-search{
		position: relative;
	}
	.Lu-F-searchImg{
		width: 32rpx;
		height: 32rpx;
		position: absolute;
		left: 26rpx;
		top: 14rpx;
	}
	.Lu-F-searchInput{
		background-color: #d7d8e9;
		width: 330rpx;
		height: 60rpx;
		border-radius: 30rpx;
		padding-left: 80rpx;
		padding-right: 80rpx;
		line-height: 60rpx;
		font-size: 24rpx;
		color: #333;
	}
	.Lu-F-banner{
		padding: 20rpx;
	}
	.Lu-F-bannerImg{
		width: 710rpx;
		height: 320rpx;
		border-radius: 10rpx;
	}
	.Lu-F-Lists{
		padding: 20rpx;
		padding-top: 0;
		background-color: #f5f5f5;
	}
	.Lu-F-List{
		padding: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;
	}
	.Lu-F-Apply{
		background-image: url('~@/static/bb.png');
	}
	.Lu-F-Bea{
		background-image: url('~@/static/mr.png');
	}
	.Lu-F-School{
		background-image: url('~@/static/sx.png');
	}
	.Lu-F-Fitness{
		background-image: url('~@/static/js.png');
	}
	.Lu-F-play{
		background-image: url('~@/static/my.png');
	}
	.Lu-F-more{
		background-image: url('~@/static/more.png');
	}
	.Lu-F-Apply,.Lu-F-Bea{
		width: 330rpx;
		height: 170rpx;
		background-repeat: no-repeat;
		background-size: 330rpx 170rpx;
	}
	.Lu-F-Bea{
		margin-left: 8rpx;
	}
	.Lu-F-title{
		font-size: 34rpx;
		letter-spacing:8rpx;
		color: #333;
		margin: 20rpx 0 0 24rpx;
		font-weight: 800;
	}
	.Lu-F-english{
		font-size: 24rpx;
		color: #666666;
		margin: 14rpx 0 0 24rpx;
		font-weight:normal;
	}
	.Lu-F-Bottom{
		margin-top: 10rpx;
	}
	.Lu-F-School,.Lu-F-Fitness{
		width: 224rpx;
		height: 160rpx;
		background-repeat: no-repeat;
		background-size: 224rpx 160rpx;
	}
	.Lu-F-Fitness,.Lu-F-mm{
		margin-left: 8rpx;
	}
	.Lu-F-mm{
		
	}
	.Lu-F-play,.Lu-F-more{
		width: 204rpx;
		height: 74rpx;
		background-repeat: no-repeat;
		background-size: 204rpx 74rpx;
		border-radius: 10rpx;
		text-align: center;
	}
	.Lu-F-title1{
		font-size: 30rpx;
		letter-spacing:8rpx;
		color: #333;
	}
	.Lu-F-english1{
		font-size: 24rpx;
		font-weight: normal;
		color: #666666;
	}
	.Lu-F-more{
		margin-top: 12rpx;
	}
	.swiper-item{
		height: 100%;
		line-height: 100%;
	}
	.Lu-F-Bullet{
		// height:50rpx !important;
	}
	.Lu-F-BulletTit{
		font-size: 24rpx;
		margin-left: 32rpx;
	}
	.Lu-F-BulletImg{
		width: 24rpx;
		height: 20rpx;
	}
	.Lu-F-Bullets{
		background-color:#f5f5f5;
		padding: 20rpx;
		padding-top: 0;
	}
	.Lu-F-Bullets1{
		background-color: #fff;
		border-radius: 10rpx;
		padding: 10rpx 20rpx 10rpx 54rpx;
	}
	.Lu-F-Populars1{
		margin-right: 20rpx;
	}
	.Lu-F-Populars{
		margin-top: 0rpx;
		margin-left: 20rpx;
		margin-right: 20rpx;
		
		.Lu-F-Popular2{
			margin-bottom: 20rpx;
		}
		.Lu-F-Popular{
			display: flex;
			align-items:center;
			justify-content: flex-start;
			position: relative;
			.Lu-F-Popularmore{
				position: absolute;
				right: 14rpx;
				font-size: 24rpx;
			}
			image{
				width: 40rpx;
				height: 60rpx;
			}
			h3{
				font-size: 42rpx;
				font-weight: 400;
				height: 60rpx;
			}
		}
		.Lu-index-renqiList{
			width: 330rpx;
			float: left;
			margin: 0 12rpx;
			
			.Lu-index-img{
				width: 330rpx;
				height: 330rpx;
				border-top-left-radius: 20rpx;
				border-top-right-radius: 20rpx;
				margin-bottom: -10rpx;
			}
			.Lu-index-infor{
				background-color: #fff; 
				border-bottom-left-radius: 20rpx;
				border-bottom-right-radius: 20rpx;
				height: 104rpx;
				padding-top: 16rpx;
				padding-left: 26rpx;
				view{
					.Lu-index-inforname{
						font-size: 32rpx;
						color: #333333;
					}
					.Lu-index-infordes{
						font-size: 24rpx;
						color: #818181;
						width: 304rpx;
						margin-top: 16rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}
				}
			}
		}
	}
	.kite-classify-cell{
		width: 544rpx;
		height: 278rpx;
		margin-right: 20rpx;
		position: relative;
		.Lu-F-PopularImg{
			border-radius: 20rpx;
		}
		image{
			width: 544rpx;
			height: 278rpx;
		}
		.Lu-F-PopularTitle{
			width: 504rpx;
			position: absolute;
			padding: 10rpx 20rpx;
			bottom: 0rpx;
			left: 0rpx;
			border-bottom-right-radius: 20rpx;
			border-bottom-left-radius: 20rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background-color: rgba(0,0,0,.6);
			.Lu-F-Popularname{
				font-size: 30rpx;
				color: #fff;
			}
			.Lu-F-Populargo{
				font-size: 24rpx;
				color: #878686;
			}
		}
	}
	.campus-item {
		position: relative;
		overflow: hidden;
		// border-top: 1px solid #f5f5f5;
		padding: 12rpx 0;
	}
	
	.campus-media {
		float: left;
		height: 160rpx;
		// line-height: 160rpx;
		// padding: 10rpx 0;
		.campus-logo {
			width: 270rpx;
			height: 160rpx;
			border-radius: 10rpx 0 0 10rpx;
			vertical-align: middle;
		}
	}
	
	.campus-body {
		margin-left: 270rpx;
		// padding-left: 20rpx;
		background-color: #fff;
		border-radius: 0 10rpx 10rpx 0;
		padding: 2rpx 0;
		height: 156rpx;
		.campus-title {
			font-size: 26rpx;
			color: #333;
			padding-top: 2rpx;
			margin-bottom: 4rpx;
			padding-left: 20rpx;
		}
	
		.campus-desc {
			font-size: 24rpx;
			color: #666666;
			height: 64rpx;
			margin-bottom: 4rpx;
			padding-left: 20rpx;
		}
		.campus-footer {
			font-size: 24rpx;
			color: #666666;
			// height: 44rpx;
			// line-height: 44rpx;
			overflow: hidden;
			white-space: nowrap;
			text-overflow: ellipsis;
			padding-left: 20rpx;
		
			.iconfont {
				font-size: 24rpx;
				margin-right: 6rpx;
				border-radius: 20rpx;
		
			}
		}
	}
	.Lu-F-iconclose{
		position: absolute;
		right: 15px;
		top: 7px;
		color: #666;
		z-index: 100;
	}
</style>
